import { query } from '@angular/animations';
import { Component } from '@angular/core';
import { Router } from '@angular/router';

// 引入Parse第三方库
import * as Parse from "parse"
(Parse as any).serverURL = "http://metapunk.cn:9999/parse"
Parse.initialize("dev")

@Component({
  selector: 'app-page-search',
  templateUrl: './page-search.component.html',
  styleUrls: ['./page-search.component.scss']
})
export class PageSearchComponent {
  title:string=''

  inputIn(e:any){
    console.log(e.target.value)
    this.title=e.target.value
  }

  //查找
  searchList:any
  searchBtn(){
    this.getDetailByName(this.title)
  }
  async getDetailByName(name:string){
    let query = new Parse.Query("goods")
    // query.equalTo("goodsName",name)
    query.contains("goodsName", name)
    let list = await query.find()
    console.log(list)
    this.searchList=list
    if(this.searchList.length==0){
      this.title="很抱歉，未能找到该商品"
    }
    else this.title=''
    return list
  }

  //进入详情页面
  goDetail(item:any) {
    console.log(item.goods);
     this.router.navigate(["./intelligent-shopping/detail"],{
        queryParams:{
            id:item.id
  }
     })
  }
  constructor(private router:Router){
  
  }

  
}
